package ;
import bee2d.display.Animation;
//import bee2d.display.AnimationSprite;
import bee2d.spritesheet.importers.AnimoImporter;
import nme.events.MouseEvent;
import nme.display.FPS;
import nme.display.SimpleButton;
import nme.display.Sprite;
import bee2d.core.Rander;
import nme.events.Event;
import nme.Lib;
import bee2d.spritesheet.Spritesheet;
import format.SWF;
import nme.system.System;
/**
 * ...
 * @author wangjian QQ:421924396
 */

class Main extends Sprite 
{
	var layer:Sprite;
	var rander:Rander;
	private var previousTime:Int;
	var fps:FPS ;
	var button:SimpleButton;
	public function new() 
	{
		super();
		layer = new Sprite();
		this.addChild(layer);
		fps = new FPS(10,10,0);
		this.addChild(fps);
		rander = new Rander(layer,true);
		Fish.initFishAssets();
		for (i in 0...150) {
			var ani = new Fish();
			ani.x = Std.int( Math.random() * 700);
			ani.y = Std.int(Math.random() * 500);
			ani.rotation = 50;
			//if (i > 50) ani.visible = false;
			rander.addChild(ani);
			
		}
		//var sprite:AnimationSprite = new AnimationSprite(Fish.fishSpriteSheet);
		//this.addChild(sprite);
		previousTime = Lib.getTimer ();
		this.addEventListener(Event.ENTER_FRAME, enterFrame);
		var swf:SWF = new SWF(ApplicationMain.getAsset ("assets/assets.swf"));
		button = swf.createButton("CloseBtn");
		button.cacheAsBitmap = true;
		button.x = 300;
		button.y = 300;
		button.addEventListener(MouseEvent.CLICK, closeHandle);
		this.addChild(button);
	}
	
	private function closeHandle(e:MouseEvent):Void 
	{
		rander.blitMode = !rander.blitMode;
		//#if cpp
		//Lib.close();
		//#else
		//System.exit(0);
		//#end
	}
	function enterFrame(e:Event):Void {
		rander.rander(Lib.getTimer() - previousTime);
		previousTime = Lib.getTimer ();
	}
}